package cn.edu.sgu.www.mhxysy.controller.chongwu_shizhuang;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.dto.chongwu_shizhuang.ChongwuShizhuangAttributeDTO;
import cn.edu.sgu.www.mhxysy.entity.chongwu_shizhuang.ChongwuShizhuangAttribute;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.chongwu_shizhuang.ChongwuShizhuangAttributeService;
import cn.edu.sgu.www.mhxysy.vo.except.AttributeVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "宠物时装属性管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/chongwu_shizhuang_attribute", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class ChongwuShizhuangAttributeController {

    private final ChongwuShizhuangAttributeService chongwuShizhuangCategoryService;

    @Autowired
    public ChongwuShizhuangAttributeController(ChongwuShizhuangAttributeService chongwuShizhuangCategoryService) {
        this.chongwuShizhuangCategoryService = chongwuShizhuangCategoryService;
    }

    @ApiOperation("添加宠物时装属性")
    @ApiOperationSupport(ignoreParameters = "id")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public JsonResult<Void> insert(@Validated ChongwuShizhuangAttributeDTO chongwuShizhuangAttributeDTO) {
        chongwuShizhuangCategoryService.insert(chongwuShizhuangAttributeDTO);

        return JsonResult.success(CustomMessages.INSERT_SUCCESS);
    }

    @ApiOperation("通过ID删除宠物时装属性")
    @RequestMapping(value = "/deleteById", method = RequestMethod.POST)
    public JsonResult<Void> deleteById(
            @ApiParam(name = "id", value = "宠物时装属性ID", required = true)
            @NotBlank(message = CustomMessages.ID_NOT_NULL) String id) {
        chongwuShizhuangCategoryService.deleteById(id);

        return JsonResult.success(CustomMessages.DELETE_SUCCESS);
    }

    @ApiOperation("通过ID修改宠物时装属性")
    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    public JsonResult<Void> updateById(@Validated ChongwuShizhuangAttributeDTO chongwuShizhuangAttributeDTO) {
        chongwuShizhuangCategoryService.updateById(chongwuShizhuangAttributeDTO);

        return JsonResult.success(CustomMessages.UPDATE_SUCCESS);
    }

    @ApiOperation("通过ID查询星石属性")
    @RequestMapping(value = "/selectAttribute", method = RequestMethod.GET)
    public JsonResult<AttributeVO> selectAttribute(
            @ApiParam(name = "shizhuangId", value = "宠物时装ID", required = true)
            @NotBlank(message = CustomMessages.ID_NOT_NULL) String shizhuangId) {
        AttributeVO attributeVO = chongwuShizhuangCategoryService.selectAttribute(shizhuangId);

        return JsonResult.success(null, attributeVO);
    }

    @ApiOperation("查询宠物时装属性列表")
    @RequestMapping(value = "/selectByShizhuangId", method = RequestMethod.GET)
    public JsonResult<List<ChongwuShizhuangAttribute>> selectByShizhuangId(
            @ApiParam(name = "shizhuangId", value = "宠物时装ID", required = false)
            @RequestParam(required = false) String shizhuangId) {
        List<ChongwuShizhuangAttribute> list = chongwuShizhuangCategoryService.selectByShizhuangId(shizhuangId);

        return JsonResult.success(null, list);
    }

}